/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/** ************************************************************************************************
 *  \file     Firewall.h                                                                      *
 *  \brief    SemiDrive Firewall driver header file.                                               *
 *                                                                                                 *
 **************************************************************************************************/

#ifndef SDRV_FIREWALL_H
#define SDRV_FIREWALL_H

/***************************************************************************************************
 *                                      Include header files                                       *
 **************************************************************************************************/
#include "lld_platform.h"
#include "firewall_platform.h"

/***************************************************************************************************
 *                                 Global Macro definition                                         *
 **************************************************************************************************/
/**
 *  \name FIREWALL Driver ID Info
 * \{
 */
/** \brief  Semi Driver Vendor ID */
#define FIREWALL_VENDOR_ID        (0x8CU)
/** \brief  FIREWALL Driver Module ID */
#define FIREWALL_MODULE_ID        (2049U)
/** \brief FIREWALL Driver Instance ID */
#define FIREWALL_INSTANCE_ID      (0x00U)
/** \} */

/**
 *  \name FIREWALL Driver Functions ID
 * \{
 */
/** \brief  Firewall_Init() function id. */
#define FIREWALL_INIT_ID          (0U)
/** \brief  Firewall_AssignDomain() function id. */
#define FIREWALL_ASSIGN_DOMAIN_ID (1U)
/** \brief  Firewall_LockDomainAssignment() function id. */
#define FIREWALL_LOCK_DOMAIN_ID   (2U)
/** \brief  Firewall_GetErrorInformation() function id. */
#define FIREWALL_GET_ERRORINFO_ID (3U)
/** \brief  Firewall_IrqHandler() function id. */
#define FIREWALL_IRQ_HANDLER_ID   (4U)
/** \brief  Firewall_Deinit() function id. */
#define FIREWALL_DEINIT_ID        (5U)
/** \brief  Firewall_SetCallback() function id. */
#define FIREWALL_SET_CALLBACK_ID  (6U)
/** \} */

/** \brief Enable read and write permissions. */
#define PERMISSION_RW             (0x00U)
/** \brief Enable read permission. */
#define PERMISSION_RO             (0x01U)
/** \brief Enable write permission. */
#define PERMISSION_WO             (0x02U)
/** \brief No permission. */
#define PERMISSION_NONE           (0x03U)

/** \brief  Firewall module uninitialized state. */
#define FIREWALL_UNINIT           (0x00U)
/** \brief  Firewall module initialized state. */
#define FIREWALL_INIT             (0x01U)

/** \brief The minimum value of register. */
#define FIREWALL_REG_VALUE_MIN    (0x00U)
/** \brief The maximum value of register. */
#define FIREWALL_REG_VALUE_MAX    (0xFFFFFFFFU)

#if (defined(CFG_PLATFORM_MCAL))
#define FIREWALL_E_ERROR(code)    (code)
#elif (defined(CFG_PLATFORM_SSDK))
#define FIREWALL_E_ERROR(code)    SDRV_ERROR_STATUS(SDRV_STATUS_GROUP_FIREWALL, (code))
#else
#error "Undefined macros CFG_PLATFORM_MCAL or CFG_PLATFORM_SSDK"
#endif /** #if (defined(CFG_PLATFORM_MCAL)) */

/***************************************************************************************************
 *                                  Global Types definition                                        *
 **************************************************************************************************/
/**
 * \brief Firewall status return code
 */
typedef enum sdrv_firewall_err_status
{
    /**< status for success. */
    FIREWALL_E_OK = 0,
    /**< Error due to API duplicated invoked FIREWALL_Init(). */
    FIREWALL_E_INIT = FIREWALL_E_ERROR(0),
    /**< Error due to API invoked without performing FIREWALL_Init(). */
    FIREWALL_E_UNINIT = FIREWALL_E_ERROR(1),
    /**< Error due to NULL_PTR passed as parameter. */
    FIREWALL_E_NULL_POINTER = FIREWALL_E_ERROR(3),
    /**< Error due to invalid master id. */
    FIREWALL_E_MAC_MASTER_ID = FIREWALL_E_ERROR(4),
    /**< Error due to invalid domain id. */
    FIREWALL_E_MAC_DOMAIN_ID = FIREWALL_E_ERROR(5),
    /**< Error due to the MAC module has been locked. */
    FIREWALL_E_MAC_LOCKED = FIREWALL_E_ERROR(6),
    /**< Error due to the unvalid number of memory ports. */
    FIREWALL_E_MPC_PORT_NUM = FIREWALL_E_ERROR(7),
    /**< Error due to the unvalid number of memory regions. */
    FIREWALL_E_MPC_REGION_NUM = FIREWALL_E_ERROR(8),
    /**< Error due to the unvalid number of peripherals. */
    FIREWALL_E_PPC_IP_NUM = FIREWALL_E_ERROR(9),
    /**< Error due to the unvalid number of apb regions. */
    FIREWALL_E_PPC_REGION_NUM = FIREWALL_E_ERROR(10),
    /**< Error due to invalid core id. */
    FIREWALL_E_DIO_CORE_ID = FIREWALL_E_ERROR(11),
    /**< Error due to invalid gpio pin channel id. */
    FIREWALL_E_DIO_CHANNEL_ID = FIREWALL_E_ERROR(12),
    /**< Error due to invalid number of cores. */
    FIREWALL_E_DIO_CORE_NUM = FIREWALL_E_ERROR(13),
    /**< Error due to invalid number of gpio pin channels. */
    FIREWALL_E_DIO_CHANNEL_NUM = FIREWALL_E_ERROR(14),
} Firewall_ErrStatus;

/** \brief The type of configuarion for the MAC module */
typedef const uint8_t *Firewall_MacConfigType;

/**
 * \brief MPC region configure.
 */
typedef struct Mpc_RegionCfg
{
    uint32_t mpcStartAddr;               /**< start address */
    uint32_t mpcEndAddr;                 /**< end address */
    uint32_t mpcDomain0Permission : 4;   /**< user permission << 2 | privilege permission */
    uint32_t mpcDomain1Permission : 4;   /**< user permission << 2 | privilege permission */
    uint32_t mpcDomain2Permission : 4;   /**< user permission << 2 | privilege permission */
    uint32_t mpcDomain3Permission : 4;   /**< user permission << 2 | privilege permission */
    uint32_t mpcDomain4Permission : 4;   /**< user permission << 2 | privilege permission */
    uint32_t mpcDomain5Permission : 4;   /**< user permission << 2 | privilege permission */
    uint32_t mpcDomain6Permission : 4;   /**< user permission << 2 | privilege permission */
    uint32_t mpcDomain7Permission : 4;   /**< user permission << 2 | privilege permission */
    uint32_t mpcDomain8Permission : 4;   /**< user permission << 2 | privilege permission */
    uint32_t mpcDomain9Permission : 4;   /**< user permission << 2 | privilege permission */
    uint32_t mpcDomain10Permission : 4;  /**< user permission << 2 | privilege permission */
    uint32_t mpcDomain11Permission : 4;  /**< user permission << 2 | privilege permission */
    uint32_t mpcDomain12Permission : 4;  /**< user permission << 2 | privilege permission */
    uint32_t mpcDomain13Permission : 4;  /**< user permission << 2 | privilege permission */
    uint32_t mpcDomain14Permission : 4;  /**< user permission << 2 | privilege permission */
    uint32_t mpcDomain15Permission : 4;  /**< user permission << 2 | privilege permission */
} Firewall_MpcRegionConfigType;

/**
 * \brief MPC memory port configure.
 */
typedef struct Mpc_MemPortCfg
{
    uint16_t mpcRegionNum;   /**< The number of regions in the specified memory port */
    uint16_t mpcBaseOffset;  /**< memory port base offset */
    const Firewall_MpcRegionConfigType *const mpcRegionCfgPtr;
    /**< the configuration of the regions */
} Firewall_MpcMemPortConfigType;

/**
 * \brief PPC address configure.
 */
typedef struct Ppc_AddrCfg
{
    uint8_t ppcDomain0UserPermission : 2;         /**< Domain0 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain0PrivilegedPermission : 2;   /**< Domain0 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain1UserPermission : 2;         /**< Domain1 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain1PrivilegedPermission : 2;   /**< Domain1 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain2UserPermission : 2;         /**< Domain2 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain2PrivilegedPermission : 2;   /**< Domain2 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain3UserPermission : 2;         /**< Domain3 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain3PrivilegedPermission : 2;   /**< Domain3 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain4UserPermission : 2;         /**< Domain4 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain4PrivilegedPermission : 2;   /**< Domain4 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain5UserPermission : 2;         /**< Domain5 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain5PrivilegedPermission : 2;   /**< Domain5 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain6UserPermission : 2;         /**< Domain6 Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain6PrivilegedPermission : 2;   /**< Domain6 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain7UserPermission : 2;         /**< Domain7 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain7PrivilegedPermission : 2;   /**< Domain7 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain8UserPermission : 2;         /**< Domain8 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain8PrivilegedPermission : 2;   /**< Domain8 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain9UserPermission : 2;         /**< Domain9 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain9PrivilegedPermission : 2;   /**< Domain9 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain10UserPermission : 2;        /**< Domain10 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain10PrivilegedPermission : 2;  /**< Domain10 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain11UserPermission : 2;        /**< Domain11 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain11PrivilegedPermission : 2;  /**< Domain11 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain12UserPermission : 2;        /**< Domain12 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain12PrivilegedPermission : 2;  /**< Domain12 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain13UserPermission : 2;        /**< Domain13 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain13PrivilegedPermission : 2;  /**< Domain13 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain14UserPermission : 2;        /**< Domain14 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain14PrivilegedPermission : 2;  /**< Domain14 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain15UserPermission : 2;        /**< Domain15 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain15PrivilegedPermission : 2;  /**< Domain15 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcApbmuxId : 4;                  /**< PPC protected APBMUX num */
    uint8_t ppcRegionN;                              /**< PPC protected Region N */
    uint32_t ppcStartAddr;                           /**< start addr */
    uint32_t ppcEndAddr;                             /**< end addr */
} Firewall_PpcAddrConfigType;

/**
 * \brief PPC ip configure.
 */
typedef struct Ppc_IpCfg
{
    uint8_t ppcDomain0UserPermission : 2;         /**< Domain0 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain0PrivilegedPermission : 2;   /**< Domain0 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain1UserPermission : 2;         /**< Domain1 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain1PrivilegedPermission : 2;   /**< Domain1 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain2UserPermission : 2;         /**< Domain2 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain2PrivilegedPermission : 2;   /**< Domain2 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain3UserPermission : 2;         /**< Domain3 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain3PrivilegedPermission : 2;   /**< Domain3 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain4UserPermission : 2;         /**< Domain4 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain4PrivilegedPermission : 2;   /**< Domain4 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain5UserPermission : 2;         /**< Domain5 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain5PrivilegedPermission : 2;   /**< Domain5 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain6UserPermission : 2;         /**< Domain6 Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain6PrivilegedPermission : 2;   /**< Domain6 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain7UserPermission : 2;         /**< Domain7 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain7PrivilegedPermission : 2;   /**< Domain7 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain8UserPermission : 2;         /**< Domain7 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain8PrivilegedPermission : 2;   /**< Domain7 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain9UserPermission : 2;         /**< Domain7 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain9PrivilegedPermission : 2;   /**< Domain7 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain10UserPermission : 2;        /**< Domain7 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain10PrivilegedPermission : 2;  /**< Domain7 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain11UserPermission : 2;        /**< Domain7 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain11PrivilegedPermission : 2;  /**< Domain7 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain12UserPermission : 2;        /**< Domain7 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain12PrivilegedPermission : 2;  /**< Domain7 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain13UserPermission : 2;        /**< Domain7 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain13PrivilegedPermission : 2;  /**< Domain7 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain14UserPermission : 2;        /**< Domain7 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain14PrivilegedPermission : 2;  /**< Domain7 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain15UserPermission : 2;        /**< Domain7 User Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcDomain15PrivilegedPermission : 2;  /**< Domain7 Privileged Permission 0:RW 1:RO 2:WO 3:NONE */
    uint8_t ppcApbmuxId : 4;                /**< PPC protected APBMUX num */
    uint8_t ppcApbmuxIpId;                         /**< ID number of IP */
} Firewall_PpcIpConfigType;

/**
 * \brief Pin configuration.
 */
typedef struct Firewall_DioChannelCfg
{
    const uint16_t *dioChannelID; /**< gpio channel id */
    uint16_t dioChannelNum;       /**< gpio channel number */
} Firewall_DioChannelCfgType;

/**
 * \brief Pin permission for the core.
 */
typedef struct Firewall_DioCoreCfg
{
    uint8_t dioUserPermission : 2;               /**< SF User Permission
                                                         0:RW 1:RO 2:WO 3:NONE */
    uint8_t dioPrivilegedPermission : 2;         /**< SF User Permission
                                                         0:RW 1:RO 2:WO 3:NONE */
    uint8_t dioCoreId : 4;                       /**< GPIO core ID
                                                         index 0:sf0 1:sf1 2:sf2 3:sf3 8(24):lp 9(25):se*/
    uint8_t didId;                               /**< GPIO Domain ID */
    const Firewall_DioChannelCfgType dioChannelCfg; /**< gpio channel id list */
} Firewall_DioCoreCfgType;

/**
 * \brief MPC interrupt status.
 */
typedef struct
{
    uint32_t mpcMemPortId : 16; /**< memport ID:0~22 */
    uint32_t mpcErrSta : 16;   /**< interrupt status
                                      1:memory access error
                                      2:register access error */
} Firewall_MpcIrqStaType;

/**
 * \brief PPC interrupt status.
 */
typedef struct
{
    uint32_t ppcApbmuxId : 16; /**< APBMUX ID:0~6 */
    uint32_t ppcErrSta : 16;     /**< interrupt status
                                      1:peripheral access error
                                      2:register  access error */
} Firewall_PpcIrqStaType;

/**
 * \brief Firewall interrupt status.
 */
typedef struct
{
    Firewall_PpcIrqStaType
        ppcErrInfo[FIREWALL_PPC_APBMUX_MAXNUM]; /**< PPC illegal access
                                                    information */
    Firewall_MpcIrqStaType
        mpcErrInfo[FIREWALL_MPC_MEMPORT_MAXNUM]; /**< MPC illegal access
                                                     information */
} Firewall_ErrInfoType;

/**
 * \brief Firewall controller type.
 */
 typedef struct Firewall_Controller Firewall_ControllerType;

/**
 * \brief Firewall callback function type.
 */
typedef void (*sdrv_firewall_callback_t)(Firewall_ControllerType *ctrl, void *userdata);

/**
 * \brief Firewall controller configuration.
 */
typedef struct
{
    const Firewall_MacConfigType *macCfgPtr;         /**< the configuration of the MAC module. */

    const Firewall_MpcMemPortConfigType *mpcCfgPtr;  /**< MPC configuration. */
    uint32_t mpcMemPortCfgNum;                       /**< the number of memory ports. */

    const Firewall_PpcIpConfigType *ppcBaseIpCfgPtr; /**< PPC ip configuration. */
    uint16_t ppcBaseIpCfgNum;                        /**< the number of ip. */
    const Firewall_PpcIpConfigType *ppcIpCfgPtr;     /**< PPC ip configuration. */
    uint16_t ppcIpCfgNum;                            /**< the number of ip. */
    const Firewall_PpcAddrConfigType *ppcAddrCfgPtr; /**< PPC address configuration. */
    uint16_t ppcAddrCfgNum;                          /**< the number of memory regions. */

    const Firewall_DioCoreCfgType *dioRuleSpaceCfgPtr; /**< the configuration of pin permission. */
    uint16_t dioCoreCfgNum;                            /**< the number of cores. */
} Firewall_ConfigType;

/**
 * \brief Firewall controller.
 */
struct Firewall_Controller
{
    uint32_t macBaseAddr;              /**< MAC module address base. */
    uint32_t Firewall_Irq;                  /**< firewall module irq number. */
    bool interruptEnable;              /**< the flag to enable interrupt */
    bool resErrEnable;                /**< the flag to enable error-response */
    uint8_t Firewall_InitStatus;       /**< firewall module initialize status. */
    sdrv_firewall_callback_t callback; /**< the callback function. */
    void *userdata;                    /**< the param of the callback function. */
    Firewall_ErrInfoType error_info;   /**< the illegal access error info of the firewall module. */
    const Firewall_ConfigType *Firewall_ConfigPtr; /**< the configuration of the firewall. */
};

/***************************************************************************************************
 *                                  Global Function Declarations                                   *
 **************************************************************************************************/
/**
 * \brief Configure firewall.
 *
 * \param[in] ctrl  the firewall instance.
 * \param[in] cfg  the configuration of the MAC/MPC/PPC/GPIO module.
 *
 * \return The result of the firewall initialization function
 * \details - return SDRV_STATUS_OK, initializa firewall success.
 *          - return SDRV_STATUS_INVALID_PARAM, invalid configuration parameter.
 */
lld_status_t Firewall_Init(Firewall_ControllerType *ctrl,
                            const Firewall_ConfigType *cfg);

/**
 * \brief Deinitialize the firewall.
 *
 * This function change the firewall instance state to FIREWALL_UNINIT,
 * and disable the interrupt of the MPC and PPC module.
 * This function does not turn off permission detection,
 * and should only called by lowpower feature.
 *
 * \param[in] ctrl  the firewall instance.
 *
 * \return The result of the firewall deinitialization function
 * \details - return FIREWALL_E_OK : Initializa firewall success.
 *          - return error code : Please refer to Firewall_ErrStatus.
 */
lld_status_t Firewall_Deinit(Firewall_ControllerType *ctrl);

/**
 * \brief Assigns the master to the specified domain.
 *
 * Assigns the specified master to a domain.
 * This function should be executed after the initialization function
 * Firewall_Init().
 *
 * \param[in] ctrl  the firewall instance.
 * \param[in] master_id  the id of the master.
 * \param[in] domain_id  the id of the domain.
 *
 * \return The result of this function.
 * \details - return FIREWALL_E_OK, Assigned the master to the domain success.
 *          - return FIREWALL_E_UNINIT: The firewall is uninitialized.
 *          - return FIREWALL_E_MAC_MASTER_ID: The master id is unvalid.
 *          - return FIREWALL_E_MAC_DOMAIN_ID: The domain id is unvalid.
 *          - return FIREWALL_E_MAC_LOCKED: The domain assignment of the master
 * is locked.
 */
lld_status_t Firewall_AssignDomain(const Firewall_ControllerType *ctrl, uint8_t master_id,
                                     uint8_t domain_id);

/**
 * \brief Lock the domain assignment of the master.
 *
 * This function lock the domain assignment of the master, should be called
 * after the initialization function Firewall_Init() or domain assignment
 * function Firewall_AssignDomain().
 *
 * \param[in] ctrl  the firewall instance.
 *
 * \return The result of this function.
 * \details - return FIREWALL_E_OK : Lock domain assignment success.
 *          - return FIREWALL_E_INIT : The firewall is uninitialized.
 *          - return FIREWALL_E_NULL_POINTER : The pointer to the MAC
 * configuration is NULL.
 */
lld_status_t Firewall_LockDomainAssignment(const Firewall_ControllerType *ctrl);

/**
 * \brief Set callback function for firewall.
 *
 * \param[in] ctrl  the firewall instance.
 * \param[in] callback  the callback function.
 * \param[in] userdata  the param of callback function.
 *
 * \return The result of this function.
 * \details - return FIREWALL_E_OK : Set callback function success.
 *          - return FIREWALL_E_NULL_POINTER : The pointer to the MAC
 * configuration is NULL.
 *          - return FIREWALL_E_UNINIT : The firewall is uninitialized.
 */
lld_status_t Firewall_SetCallback(Firewall_ControllerType *ctrl,
                                    sdrv_firewall_callback_t callback,
                                    void *userdata);

/**
 * \brief Handle firewall interrupt.
 *
 * This function clear MAC/PPC/MPC Interruption, return interrupt state.
 *
 * \param [in] irq the irq number of the firewall.
 * \param [in] ctrl sdrv firewall controller.
 *
 * \return The result of this function.
 * \details - return 0 : Handle firewall interrupt success.
 *          - return 1 : The pointer to the MAC configuration is NULL.
 *          - return 2 : The firewall is uninitialized.
 */
int32_t Firewall_Ip_IrqHandler(uint32_t irq, void *ctrl);

/**
 * \brief Get firewall illegal access infomation.
 *
 * Should enable the macro FIREWALL_INTERRUPT_EN.
 *
 * \param[in] ctrl  the firewall instance.
 * \param[in] firewall_err_info  Pointer to the buffer used by system to get the
 * information.
 *
 * \return The result of this function.
 * \details - return FIREWALL_E_OK : Set callback function success.
 *          - return FIREWALL_E_NULL_POINTER : The pointer to the MAC
 * configuration is NULL.
 *          - return FIREWALL_E_UNINIT : The firewall is uninitialized.
 */
lld_status_t Firewall_GetErrorInformation(Firewall_ControllerType *ctrl,
                                      Firewall_ErrInfoType *firewall_err_info);

#endif /* SDRV_FIREWALL_H */

/* End of file */
